var arr = [11, 7, 6, 2, 100, 76];

// 1. 快排
function quickSort(arr) {
  if (arr.length <= 1) return arr;
  var left = [],
    right = [],
    tem = arr[0];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] > tem) {
      right.push(arr[i]);
    } else {
      left.push(arr[i]);
    }
  }

  return [...quickSort(left), tem, ...quickSort(right)];
}
var arr1 = quickSort(arr);
console.log("快排", arr1);

// 2. 冒泡排序
Array.prototype.bubbleSort = function () {
  var self = this,
    tem = 0;

  for (let i = 0; i < self.length - 1; i++) {
    for (let j = 0; j < self.length - 1 - i; j++) {
      if (self[j] > self[j + 1]) {
        tem = self[j + 1];
        self[j + 1] = self[j];
        self[j] = tem;
      }
    }
  }

  return self;
};
var arr2 = arr.bubbleSort();
console.log("冒泡排序", arr2);
